const { responseTemplate } = require('../common/utils');

let loginDefaultData = {
    returnCode: 17000,
    data: {
        token: {
            accessToken:
                'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjU5NjkzMzM4LCJndy1hY2NvdW50LWluZm8iOiJ7XCJ0aWNrZXRcIjpudWxsLFwibW9iaWxlXCI6XCIxMzYxMjM0NTY3OFwiLFwidGVuYW50SWRcIjpudWxsLFwiaWRcIjpcIjFcIixcInR5cGVcIjoxLFwiYWRtaW5GbGFnXCI6dHJ1ZSxcImVtYWlsXCI6XCJyb290QHd4LmlvXCIsXCJ1c2VybmFtZVwiOlwiYWRtaW5cIixcInN0YXR1c1wiOjF9IiwidG9rZW5fbG9naW5fdGltZSI6MTY1OTY5MTUzOCwiX29ubGluZV91c2VyXyI6IjEiLCJfb25saW5lX2luZGV4XyI6MSwiX29ubGluZV91c2VyX3V1aWRfIjoiYTIyMmYwYjgtNzdkYS00M2I5LTgxNDUtYjQwYzRhZDY5OGVkIn0.A6XCDKdSddcK1krzjMl1iW2FZ2p413QbfwRUaq4IMxk',
            refreshToken: null,
            expireIn: '1800',
        },
        account: { username: 'admin', email: 'root@wx.io', mobile: '13612345678', tenantId: null, status: 1, type: 1, ticket: null, adminFlag: true, ext: null, id: '1' },
    },
    returnDesc: 'success',
};

const baseLayoutData = {
    ...responseTemplate,
    returnCode: 17000,
    data: {
        result: true,
        userInfo: {
            username: '1165480224@qq.com',
            email: 'admin',
            mobile: '13622222223',
            status: 1,
            token: '11c3a3a7e7b444c094fd10162da56c42',
            adminFlag: true,
        },
        frontCodeList: ['app_sys:welcome:dire', 'app_sys:manage:dire01', 'app_sys:manage:dire02', 'app_sys:user:query', 'app_sys:role:query', 'app_sys:role:inof01', 'app_sys:role:inof02'],
        menuList: [],
        urlList: [],
        permList: [],
    },
};

const postApi = {
    '/testApi': {
        method: 'post',
        responseFn: async (params) => {
            let type = params?.type;
            let returnCode = 17000;
            let overTime = 1000;
            if (type === '17010') {
                returnCode = 17010;
            } else if (type === 'timeover') {
                overTime = 60 * 1000;
            }
            await new Promise((resovle) => {
                setTimeout(() => {
                    resovle(true);
                }, overTime);
            });
            return {
                data: {
                    msg: 'I am test',
                },
                returnCode: returnCode,
                returnDesc: ' Request succeeded 请求成功',
                success: true,
            };
        },
    },
    '/captcha': {
        method: 'post',
        responseFn: async () => {
            await new Promise((resovle) => {
                setTimeout(() => {
                    resovle(true);
                }, 1000);
            });
            return {
                data: {
                    captcha: 'aYSs',
                    captchaNo: '898a429d-8851-4e0c-9b12-d9f704737874',
                    img: 'iVBORw0KGgoAAAANSUhEUgAAAEYAAAAjCAYAAAApF3xtAAABO0lEQVR42u2Y3QnCQBCEgx1oF9bgox2IZViFIJZ9IhIS4l72984szsC+xCC5j9nZTYYBgiAopUqZCloBBME9cM9/umf+oD0fNo17loB6wEqZPT1Bpc4eOajDbV/eJf3nz711ONfLoyxrvJ4OlBQOd98cBAUquavioEh+Sw1qhOIBk3Zj+T643FGbdsTu+CxUacEsXTFdq4OKzJH76VyoCgPigSPLFRqUB04NigmOBIwUztw12jHu3aM4KCYwEliWlqLByHYYLSgOgqmdODCWEOZbqC5qwePghOSKtp1804kCw4uGs6HgjQWjyw3LtHLDWTt8WzA6Wca4C05/MLRbuEN79hsTnNrh27WSHow2XyzTypwvngVP0kaRYEJ2mTUI8WD070lRoesO4IiM0W+7/Aeqn7wnQRAEQe31Ajv/DwwuZfpKAAAAAElFTkSuQmCC',
                },
                returnCode: 17000,
                returnDesc: ' Request succeeded 请求成功',
                success: true,
            };
        },
    },
    '/login': {
        method: 'post',
        responseFn: (data) => {
            console.log(`data = ${JSON.stringify(data)}`);
            return loginDefaultData;
        },
    },
    //基本信息
    '/baseInfo': {
        method: 'post',
        responseFn: () => {
            return baseLayoutData;
        },
    },
    '/register': {
        method: 'post',
        responseFn: () => {
            return {
                ...responseTemplate,
                data: {
                    result: true,
                },
            };
        },
    },
};

const getApi = {
    '/api/getListByGet': {
        method: 'get',
        responseFn: () => {
            return responseTemplate;
        },
    },
};

module.exports = { postApi, getApi };
